package it.tukano.treditor.modules;

import it.tukano.app.AbstractAppModule;
import it.tukano.check.Todo;
import it.tukano.treditor.engine.scene.NodeElement;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

public class TreditorFileReader extends AbstractAppModule {

    /**
     * Instance initializer
     */
    public TreditorFileReader() {
    }

    public String doLoadTreditorFile(InputStream in) throws IOException, ClassNotFoundException {
        final BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
        final ObjectInputStream objectInputStream = new ObjectInputStream(bufferedInputStream);
        final Object object = objectInputStream.readObject();
        if(object instanceof NodeElement) {
            final NodeElement root = (NodeElement) object;
            final DataModel dataModel = find(DataModel.class);
            dataModel.setSceneRoot(this, root);
            return null;
        } else {
            Todo.implementThis("introduce constant values");
            return "error";
        }
    }
}
